/*
 * MIT License
 *
 * Copyright (c) 2024-2048 冰羽
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package com.xxl.adapter.entity;

import cn.star.framework.strategy.IdStrategyAutoincrementValue;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonFormat.Shape;
import com.xxl.adapter.core.XxlEntity;
import com.xxl.job.admin.core.model.XxlJobLog;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.Lob;
import javax.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.GenericGenerator;

/**
 * XxlJobLog
 *
 * @author zhaoweiping
 *     <p style='color: red'>Created on 2024-09-23 11:06:00
 * @since 3.0.0
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Entity
@Table(
    name = "xxl_job_log",
    indexes = {@Index(columnList = "trigger_time"), @Index(columnList = "handle_code")})
@org.hibernate.annotations.Table(appliesTo = "xxl_job_log", comment = "日志")
public class JobLog extends XxlJobLog implements XxlEntity {
  /** 注释 */
  @Id
  @Column(name = "id", length = 20, nullable = false)
  @GeneratedValue(generator = IdStrategyAutoincrementValue.STRATEGY)
  @GenericGenerator(
      name = IdStrategyAutoincrementValue.STRATEGY,
      strategy = IdStrategyAutoincrementValue.STRATEGY)
  @JsonFormat(shape = Shape.STRING)
  @Comment(value = "主键")
  private long id;

  /** 执行器主键ID */
  @Column(name = "job_group", length = 11, nullable = false)
  @Comment(value = "执行器主键Id")
  private int jobGroup;

  /** 任务，主键ID */
  @Column(name = "job_id", length = 11, nullable = false)
  @Comment(value = "任务主键Id")
  private int jobId;

  /** 执行器地址，本次执行的地址 */
  @Column(name = "executor_address", length = 255)
  @Comment(value = "执行器地址，本次执行的地址")
  private String executorAddress;

  /** 执行器任务handler */
  @Column(name = "executor_handler", length = 255)
  @Comment(value = "执行器任务handler")
  private String executorHandler;

  /** 执行器任务参数 */
  @Column(name = "executor_param", length = 512)
  @Comment(value = "执行器任务参数")
  private String executorParam;

  /** 执行器任务分片参数，格式如 1/2 */
  @Column(name = "executor_sharding_param", length = 20)
  @Comment(value = "执行器任务分片参数，格式如：1/2")
  private String executorShardingParam;

  /** 失败重试次数 */
  @Column(name = "executor_fail_retry_count", length = 11, nullable = false)
  @Comment(value = "失败重试次数")
  private int executorFailRetryCount = 0;

  /** 调度-时间 */
  @Column(name = "trigger_time")
  @Comment(value = "调度时间")
  private Date triggerTime;

  /** 调度-结果 */
  @Column(name = "trigger_code", length = 11, nullable = false)
  @Comment(value = "调度结果")
  private int triggerCode;

  /** 调度-日志 */
  @Lob
  @Column(name = "trigger_msg")
  @Comment(value = "调度日志")
  private String triggerMsg;

  /** 执行-时间 */
  @Column(name = "handle_time")
  @Comment(value = "执行时间")
  private Date handleTime;

  /** 执行-状态 */
  @Column(name = "handle_code", length = 11, nullable = false)
  @Comment(value = "执行状态")
  private int handleCode;

  /** 执行-日志 */
  @Lob
  @Column(name = "handle_msg")
  @Comment(value = "执行日志")
  private String handleMsg;

  /** 告警状态：0-默认、1-无需告警、2-告警成功、3-告警失败 */
  @Column(name = "alarm_status", length = 4, nullable = false)
  @Comment(value = "告警状态：0-默认、1-无需告警、2-告警成功、3-告警失败")
  private int alarmStatus = 0;
}
